package com.ztgf.logistics.api.client.deppon;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.ExcelExport2;
import com.ztgf.common.vo.UserVO;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderEditBO;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderSaveBO;
import com.ztgf.logistics.models.bo.deppon.api.DepponBudgetBO;
import com.ztgf.logistics.models.bo.deppon.api.DepponWebsiteBO;
import com.ztgf.logistics.models.service.deppon.ILogisticsDepponOrderService;
import com.ztgf.logistics.models.vo.ExportAdminLogisticsOrderListVO;
import com.ztgf.logistics.models.vo.ExportLogisticsOrderListVO;
import com.ztgf.logistics.models.vo.deppon.LogisticsOrderVO;
import com.ztgf.logistics.models.vo.deppon.api.DepponBudgetVO;
import com.ztgf.logistics.models.vo.deppon.api.DepponWebsiteListVO;
import com.ztgf.order.models.vo.ExportAdminOrderListVO;
import com.ztgf.sys.models.service.ISessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.ztgf.logistics.models.service.deppon.ILogisticsOrderService;
import com.ztgf.logistics.models.bo.deppon.LogisticsOrderBO;
import com.ztgf.logistics.models.dto.deppon.LogisticsOrderDTO;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物流订单表控制器
 *
 * @author mxli
 * @Date 2021-09-13 22:15:56
 */

@RestController
@RequestMapping("/api/logisticsOrder")
@Slf4j
@Api(value = "LogisticsOrderApiController",tags = "物流订单表Api接口")
public class LogisticsOrderApiController {

    @DubboReference
    private ILogisticsOrderService logisticsOrderService;
    @DubboReference
    private ILogisticsDepponOrderService logisticsDepponOrderService;

    @ApiOperation(value = "添加物流订单表",notes = "添加物流订单表")
    @PostMapping(value = "/insert")
    public Result insert(LogisticsOrderSaveBO saveBO) {
        return logisticsDepponOrderService.add(saveBO);

    }

    @ApiOperation(value = "修改物流订单表",notes = "修改物流订单表")
    @PostMapping("/update")
    public Result update(LogisticsOrderEditBO saveBO){
        return logisticsOrderService.update(saveBO);
    }


    @ApiOperation(value = "撤销物流订单",notes = "撤销物流订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "物流订单表id",required = true,paramType = "query", dataType = "Long")
            ,@ApiImplicitParam(name = "remark",value = "remark",required = true,paramType = "query", dataType = "String")
    })
    @PostMapping("/cancel")
    public Result cancel(@RequestParam("id") Long id, String remark){
        return logisticsOrderService.saveCancel(id, remark);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<LogisticsOrderVO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        return logisticsOrderService.get(id);
    }

    @ApiOperation(value = "网点查询",notes = "网点查询")
    @PostMapping(value = "/queryWebsiteList")
    public Result<DepponWebsiteListVO> queryWebsiteList(DepponWebsiteBO bo) {
        return logisticsOrderService.queryWebsiteList(bo);
    }

    @ApiOperation(value = "价格试算",notes = "价格试算")
    @PostMapping(value = "/saveBudget")
    public Result<List<DepponBudgetVO>> saveBudget(DepponBudgetBO bo) {
        return logisticsOrderService.saveBudget(bo);
    }

    @ApiOperation(value = "物流订单表列表",notes = "物流订单表列表")
    @PostMapping("/queryPageList")
    public Result<Page<LogisticsOrderVO>> queryPageList(LogisticsOrderBO bo){
        return logisticsOrderService.queryPageList(bo);
    }

    @GetMapping(value = "/batchExportOrderList/{ids}")
    @ApiOperation(value = "pc批量导出物流订单表列表", notes = "pc批量导出物流订单表列表")
    public void batchExportOrderList(HttpServletResponse response, @PathVariable String ids) {
        //创建一个数组用于设置表头
        String[] attributeNames = new String[]{"物流订单号","运单号","寄送时间","结算方式","物流费用","关联订单","寄件人","始发站","收件人","目的地","用户名","货物名称","货物重量","货物数量"};
        //查询寄件记录
        List<ExportLogisticsOrderListVO> list = logisticsOrderService.queryExportList(ids);
        ExcelExport2.export(response, list, attributeNames, "寄件记录");
    }

    @GetMapping(value = "/batchAdminExportOrderList/{ids}")
    @ApiOperation(value = "admin批量导出物流订单表列表", notes = "admin批量导出物流订单表列表")
    public void batchAdminExportOrderList(HttpServletResponse response, @PathVariable String ids) {
        //创建一个数组用于设置表头
        //String[] attributeNames = new String[]{"物流订单号","运单号","寄送时间","结算方式","物流费用","寄件人","收件人"};
        String[] attributeNames = new String[]{"物流订单号","运单号","寄送时间","结算方式","物流费用","关联订单","寄件人","始发站","收件人","物流状态","目的地","用户名","货物名称","货物重量","货物数量"};
        //查询寄件记录
        List<ExportAdminLogisticsOrderListVO> list = logisticsOrderService.queryAdminExportList(ids);
        ExcelExport2.export(response, list, attributeNames, "寄件记录");
    }
}
